package com.gigi.common;

import com.alibaba.cola.dto.SingleResponse;
import com.gigi.service.manual.UploadService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 上传文件
 */
@RestController
@RequestMapping("upload")
public class UploadController {

    private final UploadService uploadPicService;

    public UploadController(UploadService uploadPicService) {
        this.uploadPicService = uploadPicService;
    }

    @ApiOperation(value = "本地")
    @PostMapping("/local")
    public SingleResponse<String> uploadLocal(@RequestParam("file") MultipartFile file) {
        return uploadPicService.uploadLocal(file);
    }

    @ApiOperation(value = "腾讯云cos")
    @PostMapping("/cos")
    public SingleResponse<String> uploadCos(@RequestParam("file") MultipartFile file) throws IOException {
        return uploadPicService.uploadCos(file);
    }

}
